package poker.controller;

import poker.guimodel.UIState;
import poker.model.GameBean;
import at.ac.tuwien.big.easyholdem.player.DerbyPlayerDAO;
import at.ac.tuwien.big.easyholdem.player.Player;

public class LoginController {
	
	public static final String AUTHENTICATED = "authenticated";
    public static final String DENIED = "denied";
    private Player formPlayer;
    private GameBean gameBean;
    private DerbyPlayerDAO derbyPlayerDAO;
    private UIState currentView;
	
	public String login()
	{
		String result = DENIED;
		
		if (formPlayer != null) {
			Player checkPlayer = derbyPlayerDAO.getPlayerByUsername(formPlayer.getUserName());
			
			if(checkPlayer != null && checkPlayer.getPassword().equals(formPlayer.getPassword()))
			{
				  result = AUTHENTICATED;
				  
				  gameBean.setPlayer(checkPlayer);
				  gameBean.setDerbyPlayerDAO(derbyPlayerDAO);
			}
        }
		
		if(result.equals(DENIED))
			currentView.setCurrentView(UIState.State.DENIED);
		
        return result;
	}
	
	public UIState getCurrentView() {
		return currentView;
	}

	public void setCurrentView(UIState currentView) {
		this.currentView = currentView;
	}


	public DerbyPlayerDAO getDerbyPlayerDAO() {
		return derbyPlayerDAO;
	}


	public void setDerbyPlayerDAO(DerbyPlayerDAO derbyPlayerDAO) {
		this.derbyPlayerDAO = derbyPlayerDAO;
	}


	public Player getFormPlayer() {
		return formPlayer;
	}


	public void setFormPlayer(Player formPlayer) {
		this.formPlayer = formPlayer;
	}

	public GameBean getGameBean() {
		return gameBean;
	}

	public void setGameBean(GameBean gameBean) {
		this.gameBean = gameBean;
	}
}
